import 'package:fixnum/fixnum.dart' as $fixnum;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../../resource/language/generated/l10n.dart';
import '../../../m_chatroom.dart';
import '../privilege/doufeng_privilege_desc_page.dart';

mixin DoufengPageModelMixin {
  GlobalKey<State> get mainKey;

  RootProxyModel get roomModel;

  void notifyListeners();

  // RideTopicData? topicData;

  /// ===================== 添加默契测试socket消息 ========
  /// 接受邀请
  // void acceptInvitation(TacitPush tacitPush) {
  //   /// 测试推送 （弹出默契测试的结果）
  //   // testTacitPushEnd();

  //   DoufengTacitDialogManager.showInvitingGsDialog(
  //     mainKey.currentState!.context,
  //     tacitPush,
  //     roomModel.channel!.channelId,
  //   );
  // }

  // void rejectionTacitAnswer(TacitPush tacitPush) {
  //   DoufengTacitDialogManager.showInvitingRefuseDialog(
  //     mainKey.currentState!.context,
  //     tacitPush,
  //   );
  // }

  // void questionTacitAnswer(TacitPush tacitPush) {
  //   /// 这里需要pop，否则回一直添加进去
  //   Navigator.pop(mainKey.currentState!.context);
  //   DoufengTacitDialogManager.showQuestionAnswerDialog(
  //     mainKey.currentState!.context,
  //     tacitPush,
  //     "question_answer_dialog",
  //   );
  // }

  // void tacitEnd(TacitPush tacitPush) {
  //   Navigator.pop(mainKey.currentState!.context);
  //   DoufengTacitDialogManager.showEndDialog(
  //     mainKey.currentState!.context,
  //     tacitPush,
  //     "question_answer_dialog",
  //   );
  // }

  /// ===================== 结束                 ========

  getTopic() async {
    // var result = await AutoRideApi.instance.getTopic();
    // if (result.isSuccess) {
    //   topicData = result.data;
    //   notifyListeners();
    // }
  }

  tacitInvite(BuildContext context) {
    // if (roomModel.channel == null) {
    //   return;
    // }
    // List<SimpleChannelUserSlot> userList = roomModel.channel!.broadcaster;
    // SimpleChannelUserSlot? gs = userList.firstWhere((element) =>
    //     element.user.id.toInt() !=
    //     UserManager.instance.currentUser?.id.toInt());
    // if (gs != null) {
    //   DoufengTacitDialogManager.showInfoDialog(context, () async {
    //     var result = await TacitApi.instance.invite(InviteTacitReq(
    //         gs: gs.user.id, channelId: roomModel.channel!.channelId));

    //     if (!result.isSuccess) {
    //       showToast("开启默契测试错误");
    //     }

    //     if (result.isSuccess) {
    //       // Navigator.pop(context);
    //     }
    //   });
    // }
  }

  tacitResponse(bool accept) {
    // TacitApi.instance.response(GsTacitResponse(
    //     accept: accept, channelId: roomModel.channel!.channelId));
  }

  tacitAnswer(int questIndex, int answerIndex) async {
    // var result = await TacitApi.instance.answer(AnswerTacitQuest(
    //     questIndex: 0,
    //     answerIndex: 0,
    //     channelId: roomModel.channel!.channelId));
    // if (!result.isSuccess) {
    //   showToast("回答问题出错：${result.errorMsg}");
    // }
  }

  openPrivilegePage(BuildContext context) {
    showModalBottomSheet(
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(16),
          topRight: Radius.circular(16),
        ),
      ),
      context: context,
      isScrollControlled: true,
      builder: (context) {
        return DoufengPrivilegeDescPage();
      },
    );
  }

  showEndPrivilegeDialog(BuildContext context) async {
    showDialog(
        context: context,
        barrierDismissible: false,
        useRootNavigator: false,
        builder: (_) {
          return Dialog(
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(16.0)),
              child: Container(
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(16),
                ),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    const SizedBox(
                      height: 20,
                    ),
                    Text(
                      T.current!.df_privilege,
                      style: const TextStyle(
                        fontSize: 16,
                        fontWeight: FontWeight.w500,
                        color: Color(0xff333333),
                      ),
                    ),
                    const SizedBox(
                      height: 30,
                    ),
                    Padding(
                      padding: const EdgeInsets.symmetric(horizontal: 25),
                      child: Text(
                        T.current!.df_privilege_end,
                        style: const TextStyle(
                          fontSize: 15,
                          fontWeight: FontWeight.w500,
                          color: Color(0xff666666),
                        ),
                      ),
                    ),
                    const SizedBox(
                      height: 30,
                    ),
                    CupertinoButton(
                        minSize: 0,
                        padding: EdgeInsets.zero,
                        child: Container(
                          decoration: BoxDecoration(
                            color: const Color(0xFFFFD400),
                            borderRadius: BorderRadius.circular(24),
                          ),
                          width: 109,
                          height: 42,
                          alignment: Alignment.center,
                          child: Text(
                            T.current!.i_know,
                            style: const TextStyle(
                              color: Color(0xff333333),
                              fontSize: 16,
                            ),
                          ),
                        ),
                        onPressed: () async {
                          Navigator.pop(context);
                        }),
                    const SizedBox(
                      height: 32,
                    ),
                  ],
                ),
              ));
        });
  }

  /// 测试弹出最后一个弹窗
  testTacitPushEnd() {
    // TacitPush testTacitPush = TacitPush(
    //   user: $fixnum.Int64(int.parse("11701150534532096")),
    //   gs: $fixnum.Int64(int.parse("16479241261743104")),
    //   end: TacitEnd(
    //     score: 100,
    //     answerRecord: [
    //       TacitAnswerRecord(
    //         userAnswer: 0,
    //         gsAnswer: 0,
    //         quest: TacitQuest(
    //           index: 0,
    //           title: "习惯叫菠萝还是凤梨",
    //           answers: [
    //             TacitAnswer(index: 0, title: "菠萝"),
    //             TacitAnswer(index: 1, title: "凤梨"),
    //           ],
    //           endTimestampMs: $fixnum.Int64(int.parse("0")),
    //         ),
    //       ),
    //       TacitAnswerRecord(
    //         userAnswer: 1,
    //         gsAnswer: 1,
    //         quest: TacitQuest(
    //           index: 2,
    //           title: "更倾向于女生素颜还是化妆",
    //           answers: [
    //             TacitAnswer(index: 0, title: "素颜"),
    //             TacitAnswer(index: 1, title: "化妆"),
    //           ],
    //           endTimestampMs: $fixnum.Int64(int.parse("11701150534532096")),
    //         ),
    //       ),
    //       TacitAnswerRecord(
    //         userAnswer: 0,
    //         gsAnswer: 1,
    //         quest: TacitQuest(
    //           index: 0,
    //           title: "习惯叫菠萝还是凤梨",
    //           answers: [
    //             TacitAnswer(index: 0, title: "菠萝"),
    //             TacitAnswer(index: 1, title: "凤梨"),
    //           ],
    //           endTimestampMs: $fixnum.Int64(int.parse("0")),
    //         ),
    //       ),
    //       TacitAnswerRecord(
    //         userAnswer: 1,
    //         gsAnswer: 0,
    //         quest: TacitQuest(
    //           index: 0,
    //           title: "习惯叫菠萝还是凤梨",
    //           answers: [
    //             TacitAnswer(index: 0, title: "菠萝"),
    //             TacitAnswer(index: 1, title: "凤梨"),
    //           ],
    //           endTimestampMs: $fixnum.Int64(int.parse("0")),
    //         ),
    //       ),
    //       TacitAnswerRecord(
    //         quest: TacitQuest(
    //           index: 1,
    //           title: "习惯叫菠萝还是凤梨",
    //           answers: [
    //             TacitAnswer(index: 0, title: "菠萝"),
    //             TacitAnswer(index: 1, title: "凤梨"),
    //           ],
    //           endTimestampMs: $fixnum.Int64(int.parse("11701150534532096")),
    //         ),
    //       ),
    //     ],
    //   ),
    //   userInfo: TacitUserInfo(
    //     uid: $fixnum.Int64(
    //       int.parse("11701150534532096"),
    //     ),
    //     avatar:
    //         "https://ugc-media.tos-cn-shanghai.volces.com/user/photo/AKfY0qo-Vw9gBMAwZxAY_pHDe5EgWcPET3cOLD6pVEw\u003d",
    //     nickName: "19999990008",
    //   ),
    //   gsInfo: TacitUserInfo(
    //     uid: $fixnum.Int64(
    //       int.parse("16479241261743104"),
    //     ),
    //     avatar:
    //         "https://ugc-media.tos-cn-shanghai.volces.com/user/photo/X91aJoGQ--puPWNuNef8wpW3NP12PTHi4SiJfNIRw-s\u003d",
    //     nickName: "兜A0070我饿哦哟",
    //   ),
    // );

    // DoufengTacitDialogManager.showEndDialog(
    //   mainKey.currentState!.context,
    //   testTacitPush,
    //   "question_answer_dialog",
    // );
  }

  void awakeTacitInvite(BuildContext context) {
    // if (roomModel.channel?.broadcaster.length == 2) tacitInvite(context);
  }
}
